package com.xdjmall.service.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.junit.jupiter.api.Test;

import com.xdjmall.dao.CarouselDao;
import com.xdjmall.dao.impl.CarouselDaoImpl;
import com.xdjmall.entity.Carousel;
import com.xdjmall.service.CarouselService;
import com.xdjmall.servlet.vo.IndexCarouselVO;

public class CarouselServiceImpl implements CarouselService {

	private CarouselDao dao = new CarouselDaoImpl();
	
//	@Test
//	public void test() throws SQLException {
//		List<IndexCarouselVO> indexCarousel = getIndexCarousel(5);
//		indexCarousel.forEach(System.out::println);
//	}

	@Override
	public List<IndexCarouselVO> getIndexCarousel(Integer num) throws SQLException {
		List<Carousel> cs = dao.selectCarouselsByNum(num);
		// 倒腾
		List<IndexCarouselVO> icvs = new ArrayList<>();
		cs.forEach(c -> {
			IndexCarouselVO icv = new IndexCarouselVO();
			icv.setCarouselId(c.getCarouselId());
			icv.setCarouselUrl(c.getCarouselUrl());
			icv.setRedirectUrl(c.getRedirectUrl());
			icvs.add(icv);
		});
		return icvs.isEmpty() ? Collections.emptyList() : icvs;
	}
}
